//
//  HomeFocusModel.m
//  OnionHome
//
//  Created by 镇景雄 on 2019/9/22.
//  Copyright © 2019年 FengJie. All rights reserved.
//

#import "HomeFocusModel.h"

@implementation HomeFocusModel

-(void)setDynamicArray:(NSArray *)dynamicArray{
    _dynamicArray = dynamicArray;
    if (dynamicArray.count ==0) {
        return;
    }
    for (NSString * imageName in dynamicArray) {
        [self.imageArray addObject:IMAGE_NAMED(imageName)];
    }
}
-(void)setImages:(NSArray *)images{
    _images = images;
    if (images.count ==0) {
        return;
    }
    for (NSString * imageName in images) {
        [self.imageArray addObject:[ImageAndVideoSaveTool getDocumentImageimageName:imageName]];
    }
    [self createImagesView:self.imageArray];
}

-(void)createImagesView:(NSMutableArray * )array{
    
    CGFloat width = (KScreenWidth - 30)/3;
    CGFloat spacing = 2;
    CGFloat x = 0;
    CGFloat y = 0;

    for (NSInteger i = 0; i < array.count; i++) {
        UIImageView * imageView = UIImageView.new;
        imageView.image = IMAGE_NAMED(@"dynamicDefut");
        imageView.image = array[i];

        [self.imagesView addSubview:imageView];
        
        if (i <3) {
            x = i * width + i * spacing;
            y = 0;
        }else{
            x = (i - 3) * width + (i - 3) * spacing;
            y = width + spacing;

        }
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(x);
            make.width.height.mas_equalTo(width);
            make.top.mas_equalTo(y);
            if (i > 3) {
                make.bottom.mas_equalTo(0);
            }
        }];
    }
}

-(NSMutableArray<UIImage *>*)imageArray{
    if(!_imageArray){
        _imageArray=[NSMutableArray new];
    }
    return _imageArray;
}
-(UIView*)imagesView{
    if(!_imagesView){
        _imagesView=[UIView new];
    }
    return _imagesView;
}
@end
